#include <string.h>

#include "my_memory.h"


#ifdef __GNUC__
uint8_t membase[MEM_MAX_SIZE] = {0};			//SRAM内存池
#else
__align(4) uint8_t membase[MEM_MAX_SIZE] = {0};			//SRAM内存池
#endif

memory_info memory;

void * my_malloc(uint32_t size)
{
    MemBlock * NewBlock;

    if(memory.MemBlockCount == 0)   // 首次申请
    {
        NewBlock = membase[0];

        memory.head = NewBlock;
        memory.MemBlockCount++;
        NewBlock->size = size;
        NewBlock->next = NewBlock;
        NewBlock->prev = NewBlock;

        return NewBlock->buffer;
    }
}






void memory_Init()
{
    memory.MemBlockCount = 0;
    memory.mem_perused = 0;
    memory.membase = membase;
    memory.head = NULL;
    memory.tail = NULL;
}